package com.itheima.controller;

import com.itheima.utils.AliyunUtil;
import io.swagger.annotations.Api;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * @author jshstart
 * @creat 2020-11-13 21:02
 */
@Api
@RestController
@RequestMapping("UpLoadFile")
public class UpLoadFileController {
    @Resource
    private RedisTemplate<String,Object> redisTemplate;
    @PostMapping("upload")
    public String upload(@RequestParam("myfile") MultipartFile multipartFile) throws   Exception {
        String path = AliyunUtil.uploadLocalDiskFileToAliyun(multipartFile.getOriginalFilename(), multipartFile.getInputStream());
       redisTemplate.opsForSet().add("file:allset",path);
       redisTemplate.opsForValue().set("file:"+path,1,30, TimeUnit.SECONDS);
        return path;
    }
}
